<%--
  Created by IntelliJ IDEA.
  User: 懒瑶瑶
  Date: 2022/5/8
  Time: 20:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>周报</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script>
        // var util;
        layui.use(['table','util','jquery','layer','form'],function () {
            var table = layui.table,util=layui.util,$=layui.jquery,layer=layui.layer,form=layui.form;

            form.verify({
                v_notallnum:function (val,item) {
                    if (/^\d+\d+\d$/.test(val)){
                        return "地址不能为数字"
                    }
                },
                v_pass:[
                    /^[\S]{10,500}$/,
                    '长度需要在10-500之间，并且不能有空格'
                ],
                num_sz:[
                    /(^$)|^\d+$/,
                    '只能填写数字'
                ],
            });
            //监听工具栏的按钮  修改，删除
            table.on('tool(demo)',function (res) {
                var row = res.data; //获取当前数据（点哪一行就是哪一行）
                var event = res.event;//获取点的是哪个按钮
                // alert(event);
                var chatId = row.chatId;
                if(event=='del'){
                    //把id传到后台去删除
                    // alert(row.empId); 弹出要删除的ID
                    layer.confirm('是否删除该谈心记录？',{
                        btn:['确定','取消']
                    },function () {//确定的回调函数
                        // alert(row.empId);测试是否进入
                        $.post("${pageContext.request.contextPath}/emp/delcord",{chatId:chatId},function (data) {
                            layer.msg(data.msg);  //使用消息层 显示删除结果
                            //重新加载table
                            table.reload('tableData',{
                                url:"${pageContext.request.contextPath}/emp/cord"
                            });
                        },"json");
                    });
                }
            });

            //监听提交
            form.on('submit(formBtn)', function () {
                var formData = new FormData($("#form1")[0]);
                $.ajax({
                    url:'${pageContext.request.contextPath}/emp/addcord',
                    type : 'POST',
                    data : formData,
                    cache: false,
                    async: false,
                    processData : false,  //必须false才会避开jQuery对 formdata 的默认处理
                    contentType : false,  //必须false才会自动加上正确的Content-Type
                    mimeType:"multipart/form-data",
                    success:function(data){
                        layer.msg('添加成功！',{icon:6,offset:"auto",time:2000});//提示框
                        table.reload('tableData',{
                            url:"${pageContext.request.contextPath}/emp/cord"
                        });
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            // parent.layer.close(index);//关闭弹出层
                            location.reload();//重新加载父页面表格

                        }, 2100);
                        location.reload();
                    }

                });
                return false;
            });



            //    转载table
            var tabBoss = table.render({
                elem:'#tableData',//指定id选择器
                cols:[[
                    {field:'chatId',title:'编号',align:'center'},
                    {field:'stuname',title:'学生姓名',align:'center'},
                    {field:'empName',title:'员工姓名 ',align:'center'},
                    {field:'addr',title:'地方',align:'center'},
                    {field:'sayscon',title:'谈心内容 ',width: 600,align:'center'},
                    {field:'chatDate',title:'谈心日期',width: 150,align:'center',templet:function(d){
                            return util.toDateString(d.chatDate,'yyyy年MM月dd日'
                            )}},
                    {toolbar:'#tools',title:'操作',width:150,align:'center',fixed:'right'}
                ]],
                url:'${pageContext.request.contextPath}/emp/cord',//请求路径
                method:'post',//请求方法
                page:true,//显示分页主键
                limits:[5,10,15,20,25,30],//切换每页行数
                limit:10,//默认的没页行数
                loading:true,//数据加载效果样式

            });
            //监听form表单数据
            form.on('submit(search-btn)',function (d) {
                var chatId = $("#chatId").val();
                var empName = $("#empName").val();
                var stuname = $("#stuname").val();
                // alert(empId + empName);
                table.reload('tableData',{//指定条件重载table
                    page: {curr:1},
                    where:{ //条件
                        chatId:chatId,
                        empName:empName,
                        stuname:stuname,
                    }
                });
            });
            //监听form表单提交  模糊查询  查看全部按钮
            form.on('submit(shuaxin-btn)',function (d) {
                location.reload("demo");//重新加载父页面表格
            });
        });
    </script>
</head>
<body><br/>
<div>
    <form class="layui-form" action="${pageContext.request.contextPath}">
<%--        查编号--%>
        <div class="layui-inline" style="font-weight:bold;font-size: 16px">编号：</div>
        <div class="layui-inline">
            <input type="text" name="chatId" id="chatId" class="layui-input" lay-verify="num_sz"/>
        </div>
<%--        查学生姓名--%>
        <div class="layui-inline" style="font-weight:bold;font-size: 16px">学生姓名：</div>
        <div class="layui-inline">
            <input type="text" name="stuname" id="stuname" class="layui-input"/>
        </div>
<%--        查员工姓名--%>
        <div class="layui-inline" style="font-weight:bold;font-size: 16px">员工姓名：</div>
        <div class="layui-inline">
            <input type="text" name="empName" id="empName" class="layui-input"/>
        </div>

        <a class="layui-btn layui-btn-normal layui-icon layui-icon-search" lay-filter="search-btn" lay-submit lay-size="sm">搜索</a>
        <a 	class="layui-btn layui-btn-warm layui-icon layui-icon-refresh" lay-filter="shuaxin-btn" lay-submit lay-size="sm">刷新</a>
    </form>
</div>

<table class="layui-table" id="tableData" lay-filter="demo" lay-size="sm"></table>
<div>
    <form class="layui-form"  id="form1"  lay-filter="form1" autocomplete="off" >
        <%--        员工,学生--%>
        <div class="layui-form-item">
            <input type="hidden" name="teacher" value="${sessionScope.empID}">
            <%--        学生--%>
            <label class="layui-form-label" style="width: 150px">谈心对象(学生)：</label>
            <div class="layui-input-inline" autocomplete="off" >
                <select style="bottom: unset" name="sayface" lay-search lay-verify="required" autocomplete="off" >
                    <option value="">学生姓名(可搜索)</option>
                    <c:forEach items="${slist}" var="s">
                        <option value="${s.stuId}" >${s.stuname}</option>
                    </c:forEach>
                </select>
            </div>
            <%--        提交--%>
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formBtn">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
        <%--        地址--%>
        <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 150px">谈心地址：</label>
            <div class="layui-input-inline">
                <input type="text" name="addr" class="layui-input" placeholder="综合楼/宿舍/教室等" lay-verify="required|v_notallnum"/>
            </div>
        </div>
        <%--        谈心内容--%>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 150px">谈心内容：</label>
            <div class="layui-input-inline">
                <textarea name="sayscon" class="layui-input" style="width: 200px;height: 100px" placeholder="谈心内容字数10-500字" lay-verify="v_pass"></textarea>
            </div>
        </div>
    </form>
</div>
<%--    定义工具栏--%>
<script type="text/html" id="tools">
    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
</script>
</body>
</html>
